package com.kingint.web.portal.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kingint.mbg.bas.entity.BasRoomState;
import com.kingint.mbg.bas.mapper.BasRoomStateMapper;
import com.kingint.mbg.sys.entity.UmsMember;
import com.kingint.web.portal.base.service.RoomStateService;
import com.kingint.web.sys.service.UmsAdminService;
import com.kingint.web.util.MenuUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@Service
@Slf4j
public class RoomStateServiceImpl implements RoomStateService {

    @Resource
    private UmsAdminService adminService;
    @Resource
    private BasRoomStateMapper roomStateMapper;

    @Override
    public List<BasRoomState> getRoomStateList() {
        UmsMember currentMember = adminService.getCurrentMember();
        Integer hotelId = currentMember.getHotelId();
        if(StringUtils.isEmpty(hotelId)){
            log.debug("该账号没有关联酒店id");
            return null;
        }
        QueryWrapper<BasRoomState> wrapper = new QueryWrapper<>();
        wrapper.eq("hotel_id",hotelId)
                .eq("status",0);
        List<BasRoomState> basRoomStates = roomStateMapper.selectList(wrapper);
        List<BasRoomState> collect=null;
        if(!CollectionUtils.isEmpty(basRoomStates)){
             collect = basRoomStates.stream().filter(s -> s.getPid() == 0).collect(Collectors.toList());
            MenuUtil.cancelRoomState(collect,basRoomStates);
        }
        return collect;
    }
}
